import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from "@vue/runtime-core";
import {Tag} from "ant-design-vue";
import {commonStatusDict, commonStatusDictMap} from '/@/utils/dict';

export const columns: BasicColumn[] = [
  {
    title: '商户号',
    dataIndex: 'mchNo',
  },
  {
    title: '商户名称',
    dataIndex: 'mchName',
  },
  {
    title: '商户简称',
    dataIndex: 'mchShortName',
  },
  {
    title: '类型',
    dataIndex: 'type',
    customRender: ({record}) => {
      const isvType = record.type;
      const enable = ~~isvType === 2;
      const color = enable ? 'orange' : 'green';
      const text = enable ? '特约商户' : '普通商户';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '服务商号',
    dataIndex: 'isvNo',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
  },
  {
    title: '状态',
    dataIndex: 'status',
    dictFormat: commonStatusDictMap,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'mchName',
    label: '商户名称',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'type',
    label: '类型',
    component: 'Select',
    componentProps: {
      options: [
        {label: '普通商户', value: 1},
        {label: '特约商户', value: 2},
      ],
    },
    colProps: {span: 6},
  },
  {
    field: 'isvNo',
    label: '服务商号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: commonStatusDict,
    },
    colProps: {span: 6},
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
    ifShow: ({values}) => !!values.id,
  },
  {
    field: 'mchName',
    label: '商户名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchShortName',
    label: '商户简称',
    component: 'Input',
    required: true,
  },
  {
    field: 'contactName',
    label: '联系人姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'contactTel',
    label: '联系人手机',
    component: 'Input',
    required: true,
  },
  {
    field: 'contactEmail',
    label: '联系人邮箱',
    component: 'Input',
  },
  {
    field: 'type',
    label: '类型',
    component: 'RadioGroup',
    defaultValue: 1,
    helpMessage: [
      '商户类型',
      '普通商户是指商户自行申请入驻微信或支付宝，无服务商协助，单独调接口。',
      '特约商户是指由微信或支付宝的服务商协助商户完成入驻，商户下单走的是服务商接口。'],
    componentProps: {
      options: [
        {label: '普通商户', value: 1},
        {label: '特约商户', value: 2},
      ],
    },
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
    required: true,
  },
  {
    field: 'isvNo',
    label: '服务商号',
    component: 'Input',
    required: ({values}) => values.type === 2,
    ifShow: ({values}) => values.type === 2,
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioGroup',
    defaultValue: 1,
    componentProps: {
      options: commonStatusDict,
    },
    required: true,
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    colProps: {lg: 24, md: 24},
  },
];
